/**
 * User: gongming
 * Date: 7/10/14
 * Time: 8:29 PM
 * Email:gongmingqm10@foxmail.com
 */
public class TriangleExercises {

    public static void main(String[] args) {
        TriangleExercises triangleExercises = new TriangleExercises();
        System.out.println("--horizontal line--");
        triangleExercises.drawHorizontalLine(8);
        System.out.println("--vertical line--");
        triangleExercises.drawVerticalLine(3);
        System.out.println("--righttriangle line--");
        triangleExercises.drawRightTriangle(3);
        System.out.println("--isosceles triangle--");
        triangleExercises.drawIsoscelesTriangle(3);
        System.out.println("--diamond triangle--");
        triangleExercises.drawDiamond(3);
        System.out.println("--name diamond--");
        triangleExercises.drawNameDiamond(3);
    }

    /**
     * To draw n asterisks in one horizontal line.
     * @param n  the number of asterisk
     */
    public void drawHorizontalLine(int n) {
        for (int i = 0; i < n; i++) {
            System.out.print("*");
        }
        System.out.println();
    }

    /**
     * To draw n asterisks in one vertical line.
     * @param n the number of asterisk
     */
    public void drawVerticalLine(int n) {
        for (int i = 0; i < n; i++) {
            System.out.println("*");
        }
    }

    /**
     * To draw a right triangle
     * @param n the height of a triangle
     */
    public void drawRightTriangle(int n) {
        for (int i = 0; i < n; i++) {
            drawHorizontalLine(i + 1);
        }
    }

    public void drawIsoscelesTriangle(int n) {
        for (int i = 0; i < n; i++) {
            for (int l = 1; l < n - i; l++) {
                System.out.print(" ");
            }
            for (int m = n - i; m < n + i + 1; m++) {
                System.out.print("*");
            }
            for (int r = n + i + 1; r < 2 * n; r++) {
                System.out.print(" ");
            }
            System.out.println();
        }

    }

    public void drawDiamond(int n) {
        drawTopTriangle(n);
        drawHorizontalLine(2 * n - 1);
        drawBottomTriangle(n);
    }


    public void drawNameDiamond(int n) {
        drawTopTriangle(n);
        System.out.println("gongming");
        drawBottomTriangle(n);
    }

    private void drawTopTriangle(int n ) {
        for (int i = 0; i < n - 1; i++) {
            for (int l = 0; l < n - i - 1; l++) {
                System.out.print(" ");
            }
            for (int m = n - i - 1; m < n + i; m++) {
                System.out.print("*");
            }
            for (int r = n + i; r < 2 * n - 1; r++) {
                System.out.print(" ");
            }
            System.out.println();
        }

    }

    private void drawBottomTriangle(int n) {
        for (int i = 0; i < n - 1; i++) {
            for (int l = 0; l < i + 1; l++) {
                System.out.print(" ");
            }
            for (int m = i + 1; m < 2 * n - i - 2; m++) {
                System.out.print("*");
            }
            for (int r = 2 * n - i - 2; r < 2 * n - 1; r++) {
                System.out.print(" ");
            }
            System.out.println();
        }
    }






}
